//Grozi Ties
// David Ing and Jae Shin Woo
//
// Grozi.RecA.ck
// This program receives OSC packets from the given port and
// responds with a sound based on the given position of the mouse
//
// This program is based off of the code from the TIES team of
// Fall 2010
//----------------------------------------------------------------

OscRecv recv; 

7000 => recv.port; // port that it listens from
recv.listen();
recv.event( "/edge, i" ) @=> OscEvent oe;

// run time of the program
while ( true ){ 
  oe => now;
  <<<"AHHH">>>;
  // asks for next messge
  while ( oe.nextMsg() != 0 ){
    oe.getInt() => int val;


    <<< "RECEIVING: ", val >>>;
    if(val<40){
      <<<"sky">>>;
      SndBuf buf => Gain g => dac;
      "sky.wav" => buf.read;
      .5 => g.gain;
      0 => buf.pos;
      Std.rand2f(.8,.9) => buf.gain;
      .2::second => now;
    }

    if(val>55){
       <<<"sky">>>;
       SndBuf buf => Gain g => dac;
       "sky.wav" => buf.read;
       .5 => g.gain;
       0 => buf.pos;
       Std.rand2f(.8,.9) => buf.gain;
       .2::second => now;  
    }

    if(val<=55&&val>=40){
      <<< "cow" >>>;
      SndBuf buf => Gain r => dac;
      "cow.wav" => buf.read;
      .5 => r.gain;
      0 => buf.pos;
      Std.rand2f(.8,.9) => buf.gain;
      .2::second => now;
    }
  }
}

